package DataBase;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import DataObjects.Supplier;

public class UpdateSupplier {
	
	
	private Supplier supplier;
	private int status=0;
	
	
	public UpdateSupplier(Supplier supp ) {
		
		this.supplier=supp;	
	}

	public void update()
	{
		SQLConnection sc=new SQLConnection();
		
		try {
			
			PreparedStatement ps1 = sc.getConnection().prepareStatement("UPDATE Supplier SET suppName=?,suppCity=?,suppStreet=?,suppZipCode=?,suppPhoneNo=?,suppPhoneNo2=?,suppMail=?,suppFax=?,suppContactMen=?,suppHouse=?,suppCellNo=?,suppStatus=? Where suppID=?;");	
			
			sc.getConnection().setAutoCommit(false);
			
			ps1.setString(1,supplier.getSuppName());
			ps1.setString(2,supplier.getCity());
			ps1.setString(3,supplier.getStreet());
			ps1.setString(4,supplier.getSuppZipCode());
			ps1.setString(5,supplier.getSuppPhoneNo());
			ps1.setString(6,supplier.getSuppPhoneNo2());
			ps1.setString(7,supplier.getSuppMail());
			ps1.setString(8,supplier.getSuppFax());
			ps1.setString(9,supplier.getSuppContactMen());
			ps1.setString(10, supplier.getHouse());
			ps1.setString(11, supplier.getSuppCellNo());			
			ps1.setString(12,supplier.getStatus());
			ps1.setString(13,supplier.getSuppId());
			ps1.executeUpdate();
			sc.getConnection().commit();
			ps1.close();
			sc.getConnection().close();
			status=1;
		}
		
		catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			status=0;
		}
		}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

}
